﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Gene
{
    class GeneLib
    {
        public static char[] karakter;
        public static String[] blok;

        GeneLib()
        {
            karakter = new char[10]; blok = new String[10];
            karakter = new char[10];
            blok = new String[10];
            karakter[0] = 'A'; blok[0] = "AAAA";
            karakter[1] = 'B'; blok[1] = "AAAT";
            karakter[2] = 'C'; blok[2] = "AAAG";
            karakter[3] = 'D'; blok[3] = "AAAC";
            karakter[4] = 'E'; blok[4] = "AATA";
            karakter[5] = 'F'; blok[5] = "AATT";
            karakter[6] = 'G'; blok[6] = "AATG";
            karakter[7] = 'H'; blok[7] = "AATC";
            karakter[8] = 'I'; blok[8] = "AAGA";
            karakter[9] = 'J'; blok[9] = "AAGT";
        }

        public static int returnIndex(char cc)
        {
            int index = 0;
            Boolean found = false;
            while (index <= 9)
            {
                if (karakter[index] == cc) found = true;
                else ++index;
            }
            if (found == true) return index;
            else return -1;
        }


        public static String Enkripsi(String plaintext) 
        {
            StringBuilder str = new StringBuilder();
            int index = 0;
            while (index <= plaintext.Length)
            {
                str.Append(blok[returnIndex(plaintext.ElementAt(index))]);
                ++index;
            }
            return str.ToString();
        }
    }
}
